package com.google.android.getwind;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Button;
import android.view.*;
import android.view.View.OnClickListener;


/*TODO LIST 
Mettre en place un bouton actualiser en menu contextuel
Mettre en place un historique.


*/
public class GetWind extends Activity {
	private  WebView myweb;

	/* Creation du menu selon contenu XML*/
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.options_menu, menu);
		return true;
		}
	
	/* Mise en place des actions sur les boutons */
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.reloading:
			GetWind.this.myweb.reload();
			return true;
		
		case R.id.quit:
			GetWind.this.finish();
			return true;
		}
		
		return false;
		};


		private OnClickListener mCorkyListener = new OnClickListener() {
		    public void onClick(View v) {
		      // do something when the button is clicked
		    	afficheweb();
		    }
		};
		
		
private void afficheweb() {
	setContentView(R.layout.anemo);
	myweb = (WebView) findViewById(R.id.myweb);
    //WebView myweb = new WebView(this); // marche pas
    
 	myweb.loadUrl("http://getwind.tododo.com/");
 	//myweb.loadUrl("http://zxing.appspot.com/scan?ret=http://getwind.tododo.com/{CODE}");
 	myweb.getSettings().setJavaScriptEnabled(true); //activer le javascript
 	myweb.getSettings().setBuiltInZoomControls(true); //activer les zooms
 	//myweb.setBackgroundDrawable(new ColorDrawable(0));

};

private void affiche_dernier_releve() {
	myweb = (WebView) findViewById(R.id.myweb);
    //WebView myweb = new WebView(this); // marche pas
    
 	myweb.loadUrl("http://getwind.tododo.com/?action=dernierreleve");
 	//myweb.loadUrl("http://zxing.appspot.com/scan?ret=http://getwind.tododo.com/{CODE}");
 	myweb.setBackgroundColor(0); //marche nick
 	//myweb.setBackgroundDrawable(new ColorDrawable(0)); //marche pas

};

	
    @Override
    public void onCreate(Bundle icicle)
    {
    super.onCreate(icicle);        
    setContentView(R.layout.main);
    
    Button button = (Button)findViewById(R.id.button);
    // Register the onClick listener with the implementation above
    button.setOnClickListener(mCorkyListener);
    
    affiche_dernier_releve();
    

    
    }
    
    
}